package main

import "fmt"
import "math"
import "time"
import "flag"

// var ip = flag.Int("flagname", 1234, "help message for flagname")
var input = flag.Int64("num", 1234, "help message for flagname")

func sqr(num int64) int64 {
	// fmt.Println("sqr:	", int64(math.Sqrt(float64(num))))
	return int64(math.Sqrt(float64(num)))
}
func fact(num int64, ch chan int64) {
	// ch := make(chan int64)
	// sqrtnum:= sqr(num)
	// for i:=int64(2); i <= sqrtnum; {
	for i := int64(2); i <= sqr(num); {
		if num%i == 0 {
			// fmt.Println(num)
			ch <- i
			num = num / i
			continue
		}
		// fmt.Println("i: ", i)
		i++
	}
	if num > 1 {
		ch <- num
	}
	close(ch)
}
func main() {
	flag.Parse()
	ch := make(chan int64)
	fmt.Println("input: ", *input)

	start_time := time.Now()

	go fact(*input, ch)
	var sum int64 = 1
	for f := range ch {
		sum *= f

		fmt.Println("fact: ", f)
	}
	fmt.Println("sum: ", sum)
	end_time := time.Now()

	duration := end_time.Sub(start_time)
	fmt.Println(duration)

}
